package com.wzb.mybatisplus.bitaction.electrumaction.btc01;

import org.bitcoinj.core.*;
import org.bitcoinj.crypto.*;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptBuilder;

import java.security.SecureRandom;

public class SimpleBitcoinConverter {

    private static final NetworkParameters MAINNET = MainNetParams.get();

    public static void generateBasicAddresses(String wifPrivateKey) {
        try {
            ECKey ecKey = DumpedPrivateKey.fromBase58(MAINNET, wifPrivateKey).getKey();

            // P2PKH (1开头)
            String p2pkh = LegacyAddress.fromKey(MAINNET, ecKey).toString();

            // P2SH (3开头)
            Script p2wpkhScript = ScriptBuilder.createP2WPKHOutputScript(ecKey);
            Script p2shScript = ScriptBuilder.createP2SHOutputScript(p2wpkhScript);
            String p2sh = LegacyAddress.fromScriptHash(MAINNET, p2shScript.getPubKeyHash()).toString();

            // Bech32 (bc1q开头)
            SegwitAddress bech32 = SegwitAddress.fromKey(MAINNET, ecKey);

            // 1. 生成新私钥





            System.out.println("P2PKH (1开头): " + p2pkh);
            System.out.println("P2SH (3开头): " + p2sh);
            System.out.println("Bech32 (bc1q开头): " + bech32);
            System.out.println("Taproot (bc1p开头): 需要更新bitcoinj版本支持");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
        generateBasicAddresses("KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rsSX81iTD2Gw");

    }
}
